#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>

#define Max_size 50

typedef struct //顺序串
{
    char str[Max_size];
    int length;
} SqlString;

void findFirstLongestDuplicateSubstring(SqlString s, int &startIndex, int &subStringLength)
{
    for (int i = 1; i * 2 <= s.length; ++i)
    {
        if (s.length % i == 0)
        {
            bool match = true;
            int j = i;
            for (; j < s.length; ++j)
            {
                if (s.str[j] != s.str[j - i])
                {
                    match = false;
                    break;
                }
            }
            if (match)
            {
                startIndex = i,
                subStringLength = j - i;
            }
        }
    }
}

int main()
{
    SqlString s;
    strcpy(s.str, "ABABCBSDABC");
    s.length = strlen(s.str);
    int stratindex, subStringLength;
    findFirstLongestDuplicateSubstring(s, stratindex, subStringLength);
    printf("串S的最长重复子串的下标和长度为:%d  %d\n", stratindex, subStringLength);
    return 0;
}